﻿using System;
using Fly.Data;
using FlyWebFrame.Model;
using System.IO; 

namespace FlyWebFrame.Action.admin
{
    public class forgotpass : Fly.Web.Action.Handler
    {
        public string username = "";
        public string login_script = "";

        public void Handle()
        {
            if (Admin.Logged())
            {
                Redirect("/admin");
            }

            SetView("/html/admin/forgotpass.htm");
            username = Form["username"];
            if (Form["submited"] == "true")
            {
                Admin admin = new Admin();
                admin.Name = Form["username"];
                
                string rStr = Path.GetRandomFileName();
                admin.Pass = rStr.Replace(".", ""); // For Removing the .
                if (admin.ResetPass())
                {
                    Refresh();
                }
                else
                {
                    login_script += "$('#login_error').html('Lỗi kết nối.');";
                }

            }

        }
    }
}